﻿#pragma once
#include <iostream>
#include <opencv2/opencv.hpp> 
#include <opencv2/core/core.hpp>


namespace analysis_img
{


	class imageFilter_AnaImg
	{
	public:
		imageFilter_AnaImg(){
			kernel = new double[win * win];
		}
		~imageFilter_AnaImg(){
			delete[] kernel;
		}

#ifndef OPGPU 
		void impoccess(cv::Mat &, cv::Mat &, cv::Mat &, cv::Mat &, float, cv::Mat& onoise, unsigned long &n);
#else
		void impoccess(cv::Mat &, cv::Mat &, cv::Mat &, cv::Mat &, cv::Mat &, float, unsigned long &n, Buffer &bf);

		static void doCudaInit(){
			int num_devices = cv::cuda::getCudaEnabledDeviceCount();
			if (num_devices == 0)
			{
#ifdef OFFLINE
				std::cout << "Error : This Computer has No GPUs\n";
#endif
				return;
			}
			int device_id = -1;
			for (int i = 0; i < num_devices; ++i)
			{
				cv::cuda::DeviceInfo dev_info(i);
				device_id = i;
				if (!dev_info.isCompatible())
				{
#ifdef OFFLINE
					std::cout << "GPU module isn't built for GPU #" << i << " ("
						<< dev_info.name() << ", CC " << dev_info.majorVersion()
						<< dev_info.minorVersion() << "\n";
#endif
					return;
				}
			}
			cv::cuda::setDevice(device_id);

			cv::cuda::GpuMat xwb(10, 10, CV_32F); //初始化设备上下文
		}

#endif

		void OtsuThreshold(const cv::Mat &imgGray, int &);

	protected:
		void mh(float);
	private:
		double *kernel;
		std::vector< std::vector<float> > tpl;
		const static short win = 5;
	};

};